package com.yjd.comm.base.concurrent.task;

import java.util.ArrayList;
import java.util.List;

import com.yjd.comm.util.FrameUtil;

public class TaskDisposeDemo {

	public static void main(String[] args) throws Exception {
		long startTime = System.currentTimeMillis();
		List<SmsTaskItem<String>> taskItems = new ArrayList<SmsTaskItem<String>>();
		boolean moreThread = true;
		for (int i = 0; i <= 100; i++) {
			taskItems.add(new SmsTaskItem<String>("短信内容:" + i,i));
		}
		new DefaultTaskDispose(moreThread, 5).taskDipose(taskItems,
				new ITaskHandler<SmsTaskItem<String>>() {

					@Override
					public void dispose(ITaskItem<SmsTaskItem<String>> item) {
						try {
							Thread.sleep(10);
								System.out.println(FrameUtil.json(item));
								if(item.getItem().getI()==50){
									item.getItem().setI(0);
									throw new RuntimeException("出错咯");
								}
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}


					
				});
		System.out.println("处理完咯,哈哈哈哈,耗时(ms)："
				+ (System.currentTimeMillis() - startTime));
	}

	@SuppressWarnings({ "hiding", "rawtypes" })
	public static class SmsTaskItem<String> implements ITaskItem {

		public String smsContent;
		public int i=0;

		public SmsTaskItem(String smsContent,int i) {
			this.smsContent = smsContent;
			this.i = i;
		}

		@Override
		public String getItem() {
			return this.smsContent;
		}

		public int getI() {
			return i;
		}

		public void setI(int i) {
			this.i = i;
		}
		
	}

}
